﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AIS.SDK.Api;
using AIS.SDK.Api.ApiResponses;
using AIS.SDK.Common;
using AIS.SDK.Model;
using Newtonsoft.Json;

namespace AIS.SDK.Api.Requests
{
    public class TokenrequestV2 : ApiRequest<AccessTokenResponse>
    {
        public TokenrequestV2(AppIdentication id)
        {
            AppIdentity = id;
        }

        public AppIdentication AppIdentity { get; set; }

        internal override string Method
        {
            get { return "POST"; }
        }

        protected override string UrlFormat
        {
            //get { return "/v2/tokenrequest"; }
            get { return "/login"; }

        }

        internal override string GetUrl()
        {
            return  GlobalVariables.GetAISServerUrl() + UrlFormat ;
        }

        protected override bool NeedToken
        {
            get { return false; }
        }

        internal override void Validate()
        {
            if (AppIdentity == null)
            {
                throw new ArgumentNullException("AppIdentity");
            }
        }

        public override string GetPostContent()
        {
            JsonSerializerSettings settings = new JsonSerializerSettings()
            {
                NullValueHandling = NullValueHandling.Ignore,
                DefaultValueHandling = DefaultValueHandling.Ignore

            };
            return JsonConvert.SerializeObject(AppIdentity, settings);
        }

        public override Dictionary<string, string> Headers()
        {
            Dictionary<string, string> dic = new Dictionary<string, string>();

            dic.Add("ContentType", "application/json");

            return dic;
        }
    }
}
